package com.qy.controller.manage;

import com.github.pagehelper.PageHelper;
import com.qy.base.core.PageBean;
import com.qy.base.core.Result;
import com.qy.base.core.ResultGenerator;
import com.qy.model.MemberOrder;
import com.qy.service.MemberOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by zaq on 2018/07/10.
*/
@RestController("Manage-MemberOrderController")
@RequestMapping("/manage/member/order")
public class MemberOrderController {
    @Resource
    private MemberOrderService memberOrderService;

    @PostMapping("/add")
    public Result add(@RequestBody MemberOrder memberOrder) {
        memberOrderService.save(memberOrder);
        return ResultGenerator.successResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Integer id) {
        memberOrderService.deleteById(id);
        return ResultGenerator.successResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody MemberOrder memberOrder) {
        memberOrderService.update(memberOrder);
        return ResultGenerator.successResult();
    }

    @GetMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        MemberOrder memberOrder = memberOrderService.findById(id);
        return ResultGenerator.successResult(memberOrder);
    }

    @GetMapping("/list")
    public Result list(PageBean<MemberOrder> page) {
        PageHelper.startPage(page.getPageNum(),page.getSize());
        List<MemberOrder> list = memberOrderService.findAll();
        page.setList(list);
        return ResultGenerator.successResult(page);
    }

//    会员订单列表
    @GetMapping("/selectMemberOrderList")
    public Result selectMemberOrderList(PageBean<MemberOrder> page,Integer type ,String content){
        MemberOrder memberOrder = new MemberOrder();
        if (type == 1){
            memberOrder.setOrder_number(content);
        }else if (type == 2){
            memberOrder.setName(content);
        }else if (type ==3){
            memberOrder.setPhone(content);
        }

        PageHelper.startPage(page.getPageNum(),page.getSize() ,"add_time desc");
        List<MemberOrder> list = memberOrderService.selectMemberOrderList(memberOrder);
        page.setList(list);
        return ResultGenerator.successResult(page);
    }
}
